package project.parser.ast.exps.op.unary;

import project.environments.DynamicEnv;
import project.environments.StaticEnv;
import project.environments.Value;
import project.parser.ast.exps.Exp;
import project.parser.ast.types.PrimType;
import project.parser.ast.types.Type;
import project.parser.ast.util.EvalUtil;
import project.parser.ast.util.TypecheckUtil;
import project.parser.ast.values.IntValue;
import project.parser.tokenizer.TokenType;

public class Minus extends UnaryOp {

	public Minus(Exp exp) {
		super(exp);
	}

	@Override
	protected String opToString() {
		return TokenType.SUB.toString();
	}

	@Override
	public Type typecheck(StaticEnv senv) {
		return TypecheckUtil.checkType(senv, PrimType.NUMBER_TYPE, exp);
	}

	@Override
	public Value evaluate(DynamicEnv denv) {
		return new IntValue(-EvalUtil.evalIntArgs(denv, exp)[0]);
	}

}
